package com.xidian.zhiancloud.service.riskcontrol.riskidenva;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xidian.zhiancloud.dao.riskcontrol.riskidenva.TRiskAssessmentMeasuresMapper;
import com.xidian.zhiancloud.dao.riskcontrol.riskidenva.TRiskValueLevelMapper;
import com.xidian.zhiancloud.model.riskcontrol.TRiskAssessmentMeasuresList;
import com.xidian.zhiancloud.model.riskcontrol.TRiskValueLevelList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * 风险评价措施表
 */
@Service
public class TRiskAssessmentMeasuresService extends ServiceImpl
        <TRiskAssessmentMeasuresMapper, TRiskAssessmentMeasuresList> {

    @Autowired
    TRiskAssessmentMeasuresMapper tRiskAssessmentMeasuresMapper;

    @Autowired
    HttpServletRequest request;

    @Autowired
    TRiskValueLevelMapper tRiskValueLevelMapper;

    //风险评价-检查项-评价-添加风险评价措施
    public int insertTRiskAsseMeas(TRiskAssessmentMeasuresList data){

        int res = tRiskAssessmentMeasuresMapper.insertTRiskAsseMeas(data);
        TRiskValueLevelList valueLevel = new TRiskValueLevelList();
        if(res != 0){
            valueLevel.setCompanyId(data.getCompanyId());
            valueLevel.setRiskAssmeaId(data.getId().intValue());
            valueLevel.setExiRiskValue(request.getParameter("exiRiskValue"));
            valueLevel.setExiApprLevel(request.getParameter("exiApprLevel"));
            valueLevel.setExiRiskLevel(request.getParameter("exiRiskLevel"));
            valueLevel.setExiRiskColor(request.getParameter("exiRiskColor"));
            valueLevel.setExiRiskConLevel(request.getParameter("exiRiskConLevel"));
            valueLevel.setAdvRiskValue(request.getParameter("advRiskValue"));
            valueLevel.setAdvApprLevel(request.getParameter("advApprLevel"));
            valueLevel.setAdvRiskLevel(request.getParameter("advRiskLevel"));
            valueLevel.setAdvRiskColor(request.getParameter("advRiskColor"));
            valueLevel.setAdvRiskConLevel(request.getParameter("advRiskConLevel"));
        }
        return tRiskValueLevelMapper.insterValueLevel(valueLevel);
    }

    //风险评价-检查项-评价-修改风险评价措施
    public int updateTRiskAsseMeas(String id,TRiskAssessmentMeasuresList data){
       int res = tRiskAssessmentMeasuresMapper.updateTRiskAsseMeas(Long.valueOf(id),data);
        TRiskValueLevelList valueLevel = new TRiskValueLevelList();
        Integer riskAssmeaId = data.getId().intValue();
        if(res != 0){
            valueLevel.setExiRiskValue(request.getParameter("exiRiskValue"));
            valueLevel.setExiApprLevel(request.getParameter("exiApprLevel"));
            valueLevel.setExiRiskLevel(request.getParameter("exiRiskLevel"));
            valueLevel.setExiRiskColor(request.getParameter("exiRiskColor"));
            valueLevel.setExiRiskConLevel(request.getParameter("exiRiskConLevel"));
            valueLevel.setAdvRiskValue(request.getParameter("advRiskValue"));
            valueLevel.setAdvApprLevel(request.getParameter("advApprLevel"));
            valueLevel.setAdvRiskLevel(request.getParameter("advRiskLevel"));
            valueLevel.setAdvRiskColor(request.getParameter("advRiskColor"));
            valueLevel.setAdvRiskConLevel(request.getParameter("advRiskConLevel"));
        }
        return tRiskValueLevelMapper.updateValueLevel(riskAssmeaId,valueLevel);
    }

    public List<TRiskAssessmentMeasuresList> getById
            (Long companyId,String tramId){
        return tRiskAssessmentMeasuresMapper.getById(companyId,tramId);
    }

    //风险辨识评价计划-风险评价按钮-检查项-评价按钮
    public List<TRiskAssessmentMeasuresList>
        getByRisIdAndRiskpointsIdAndCheckitemsId
            (Long companyId,String taskAllocatId,String checkitemsId){
        return tRiskAssessmentMeasuresMapper
            .getByRisIdAndRiskpointsIdAndCheckitemsId(companyId,taskAllocatId, checkitemsId);
    }

    /**
     * id放入list
     * @param id id(多个已逗号分隔)
     * @return List集合
     */
    public List<String> getList(String id) {
        List<String> list = new ArrayList<String>();
        String[] str = id.split(",");
        for (int i = 0; i < str.length; i++) {
            list.add(str[i]);
        }
        return list;
    }

    public int updateIdAndAssessMeas(String riskAssmeaId){
        String exiengtechnicalMeasures=request.getParameter
                ("exiengtechnicalMeasures");
        String eximanagementMeasures=request.getParameter("eximanagementMeasures");
        String exitraieducatMeasures=request.getParameter("exitraieducatMeasures");
        String exipersprotecMeasures=request.getParameter("exipersprotecMeasures");
        String exiemergencyMeasures=request.getParameter("exiemergencyMeasures");
        return tRiskAssessmentMeasuresMapper.updateIdAndAssessMeas
                (riskAssmeaId,exiengtechnicalMeasures,eximanagementMeasures,
                        exitraieducatMeasures,exipersprotecMeasures,
                        exiemergencyMeasures);
    }

}
